/********************************** (C) COPYRIGHT *******************************
* File Name          : main.c
* Author             : WCH
* Version            : V1.0.0
* Date               : 2021/08/08
* Description        : Main program body.
*********************************************************************************
* Copyright (c) 2021 Nanjing Qinheng Microelectronics Co., Ltd.
* Attention: This software (modified or not) and binary are used for 
* microcontroller manufactured by Nanjing Qinheng Microelectronics.
*******************************************************************************/

/*
 *@Note
 GPIO routine:
 PA0 push-pull output.

*/

#include "ch32f20x_gpio.h"
#include "debug.h"
#include "common_type.h"
#include "driver.h"
#include "motor.h"
#include "FreeRTOS.h"
#include "task.h"
#include "string.h"
#include "interact.h"
#include "malloc.h"

/* Global define */
#define THREAD_MOTOR_PRIO      3
#define THREAD_MOTOR_SIZE     512

#define THREAD_INTERACT_PRIO      2
#define THREAD_INTERACT_SIZE     512


/* Global Variable */
TaskHandle_t motor_Handler;
TaskHandle_t interact_Handler;

/*********************************************************************
 * @fn      ch32f203_boardInit
 *
 * @brief   让板子可以正常工作
 *
 * @return  none
 */
void ch32f203_boardInit(void)
{
    NVIC_PriorityGroupConfig( NVIC_PriorityGroup_2 );
    Delay_Init();
    serialInit(921600);
    //serialInit(115200);
    printf( "SystemClk:%ld\r\n", SystemCoreClock );
    printf( "ch32f203 run\r\n" );
}

/*********************************************************************
 * @fn      main
 *
 * @brief   Main program.
 *
 * @return  none
 */
int main( void )
{

    ch32f203_boardInit();
                    
    xTaskCreate((TaskFunction_t )thread_motor,
                    (const char*    )"motor thread",
                    (uint16_t       )THREAD_MOTOR_SIZE,
                    (void*          )NULL,
                    (UBaseType_t    )THREAD_MOTOR_PRIO,
                    (TaskHandle_t*  )&motor_Handler);

    xTaskCreate((TaskFunction_t )thread_interact,
                    (const char*    )"interact thread",
                    (uint16_t       )THREAD_INTERACT_SIZE,
                    (void*          )NULL,
                    (UBaseType_t    )THREAD_INTERACT_PRIO,
                    (TaskHandle_t*  )&interact_Handler);
    
    vTaskStartScheduler();
    /*不会再返回*/
}
